﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbActionLogDal
	{
		public DbActionLogDal()
		{
		}
 		#region Insert
 		public static int Insert(DbActionLog dbActionLog)
		{	
			string sql = @"Insert Into DbActionLog (
					AUId,
					ANote,
					AIpaddress,
					ADateTime,
					AOS,
					ABrowse
				) values('{0}','{1}','{2}','{3}','{4}','{5}')";
			sql = string.Format(sql,
					SqlHelper.String(dbActionLog.AUId),
					SqlHelper.String(dbActionLog.ANote),
					SqlHelper.String(dbActionLog.AIpaddress),
					dbActionLog.ADateTime,
					SqlHelper.String(dbActionLog.AOS),
					SqlHelper.String(dbActionLog.ABrowse)
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbActionLog dbActionLog)
		{	
			string sql = @"Update DbActionLog set 

					AUId= '{0}',
					ANote= '{1}',
					AIpaddress= '{2}',
					ADateTime= '{3}',
					AOS= '{4}',
					ABrowse= '{5}'
				where

					AId= {6}";
			sql = string.Format(sql,
					SqlHelper.String(dbActionLog.AUId),
					SqlHelper.String(dbActionLog.ANote),
					SqlHelper.String(dbActionLog.AIpaddress),
					dbActionLog.ADateTime,
					SqlHelper.String(dbActionLog.AOS),
					SqlHelper.String(dbActionLog.ABrowse),
					dbActionLog.AId);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 aId)
		{
		
			string sql = @"Delete from DbActionLog where 
					AId= {0}";
			sql = string.Format(sql,
					aId
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbActionLog a "; 
			return SqlHelper.Select(sql);
		}
				
		public static DbActionLog Select(Int32 aId)
		{
			DbActionLog dbActionLog = null;
			string sql = @"select a.* from DbActionLog a  where
					a.AId= {0}
";
			sql = string.Format(sql,
					aId
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				dbActionLog = new DbActionLog(ds.Tables[0].Rows[0]);					
			return dbActionLog;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbActionLog a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbActionLog a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbActionLog a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
